<?php

ini_set('output_buffering','on');
ini_set('zlib.output_compression', 0);

ob_end_clean();
ob_start();


echo '<script language="javascript">window.opener.document.getElementById("information").innerHTML="処理中......"</script>';
echo str_repeat(' ', 4096);

ob_flush();
flush();
// Total processes
$total = 10;
 
// Loop through process
//echo '<script language="javascript">alert(parent)</script>';
for($i=1; $i<=$total; $i++){
    // Calculate the percentation
    $percent = intval($i/$total * 100)."%";
 
    // Javascript for updating the progress bar and information
    echo '<script language="javascript">
    parent.document.getElementById("progress").innerHTML="<div style=\"position:absolute;left:0px;width:'.$percent.';background-color:#00ee00;\">&nbsp;</div>";
    parent.document.getElementById("information").innerHTML="処理中. . . '.$i.' row(s) processed.";  </script>';
    
    
    // This is for the buffer achieve the minimum size in order to flush data
    echo str_repeat('*',1024 * 16);
 
    // Send output to browser immediately
    ob_flush();
    flush();
 
    // Sleep one second so we can see the delay
    sleep(1);
}
 
// Tell user that the process is completed
echo '<script language="javascript">window.opener.document.getElementById("information").innerHTML="Process completed"</script>';

?>
